package domain;

import java.util.UUID;

public class AuthorNamePair {

	private String authorNameA;
	private UUID authorIdA;
	private String authorNameB;
	private UUID authorIdB;
	
	public AuthorNamePair(Author authorA, Author authorB) throws Exception {
		if (authorA == null)
			throw new Exception("AuthorA cannot be null.");
		if (authorB == null)
			throw new Exception("AuthorB cannot be null.");
		if (authorA.equals(authorB))
			throw new Exception("AuthorA cannot be the same as AuthorB.");
	
		this.authorNameA = authorA.getFullName();
		this.authorIdA = authorA.getAuthorID();
		this.authorNameB = authorB.getFullName();
		this.authorIdB = authorB.getAuthorID();
	}
	
	public String getAuthorNameA() { return this.authorNameA; }
	public UUID getAuthorIdA() { return this.authorIdA; }
	public String getAuthorNameB() { return this.authorNameB; }
	public UUID getAuthorIdB() { return this.authorIdB; }

	public boolean isMatch(String authorNameA, String authorNameB) {
		if (this.authorNameA.equalsIgnoreCase(authorNameA))
			return this.authorNameB.equalsIgnoreCase(authorNameB);
		else
			return this.authorNameA.equalsIgnoreCase(authorNameB) && 
					this.authorNameB.equalsIgnoreCase(authorNameA);
	}
	

	@Override
	public String toString() {
		return String.format("Author Name Pair: %s/%s", this.authorNameA, this.authorNameB);
	}
	
	@Override
	public boolean equals(Object obj) {
		if (!AuthorNamePair.class.isInstance(obj))
			return false;
		
		AuthorNamePair other = (AuthorNamePair)obj;
		if (this.authorNameA.equalsIgnoreCase(other.authorNameA))
			return this.authorNameB.equalsIgnoreCase(other.authorNameB);
		else
			return this.authorNameA.equalsIgnoreCase(other.authorNameB) && 
					this.authorNameB.equalsIgnoreCase(other.authorNameA);
	}

}
